#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int smallestRangeI(vector<int>& nums, int k) {
        int max1 = -1, min1 = INT_MAX;
        int n = nums.size();
        if (n == 1) return 0;
        for (int i = 0; i < n; i++)
        {
            if (nums[i] > max1)
            {
                max1 = nums[i];
            }
            if (nums[i] < min1)
            {
                min1 = nums[i];
            }
        }
        if (max1 - k < min1 + k) return 0;
        else return max1 - k - min1 - k;
    }
};